# -*- coding: utf-8 -*-
# @Author: Carl_DJ
# @Date:   2021-01-15


from flask import Flask, request
from flask_cors import CORS

ret="test.log"
log="msg.log"

app = Flask(__name__)
CORS(app, supports_credentials=True)


@app.route('/check/<username>')

def check_username(username=None):
    if username == 'admin':
        return readfile()
    elif username == 'superuser':
        open(ret, 'w').close()
    elif username == 'user':
        name = request.args.get('name', 'default value')
        print('name:%s' % (name))
        f = open(log, "a", encoding='utf-8')
        f.write(name)
        f.write('\n')
        f.close()

def readfile():
    with open(ret,encoding='utf-8') as fp:
        content=fp.read()
    fp.close()
    return content.strip()

if __name__ == "__main__":
    app.run()

